package com.wang.di.core.abs;

import com.wang.di.core.bean.BaseBean;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;

public abstract class AbstractNameBean extends BaseBean {
    protected String name = "";

    public AbstractNameBean(Class clz, Annotation withNameAnno) {
        super(clz, withNameAnno);
        try {
            String name = (String) withNameAnno.getClass().getMethod("name").invoke(withNameAnno);
            if (name == null || "".equals(name)) {
                String clzName = clz.getSimpleName();
                name = Character.toLowerCase(clzName.charAt(0)) + clzName.substring(1);
            }
            this.name = name;
        } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean check(Object... cond) {
        return this.name.equals(cond[0]);
    }
}
